package com.g2.admin.common.ext;

import com.g2.admin.common.constant.RedisConstants;
import com.g2.admin.model.po.AuthAuthorityPo;
import com.g2.admin.service.AuthAuthorityService;
import com.g2.admin.utils.RedisUtil;
import com.g2.admin.utils.RegularUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.List;
import java.util.stream.Collectors;

@Component
@Slf4j
public class InitData {
    @Autowired
    private AuthAuthorityService authorityService;
    @Autowired
    private RedisUtil redisUtil;

    @PostConstruct
    public void initMerchants() {
//        log.info("开始缓存初始化");
//        String authPathKey = RedisConstants.getKeyAuthPath();
//        redisUtil.delete(authPathKey);
//        log.info("开始初始化权限缓存数据");
//        List<AuthAuthorityPo> authorityPos = authorityService.getAuthCodeANdPath();
//        if (null != authorityPos) {
//            redisUtil.putAll(authPathKey, authorityPos.stream().collect(Collectors.toMap(AuthAuthorityPo::getCode, t -> RegularUtil.getPathPattern(t.getHref()))));
//        }
        log.info("结束缓存初始化");
    }
}
